home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / carnival.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  8KB  |  280 lines

  1. /*****************************************************************************/
  2. /*                                                                           */
  3. /*                    (C) Copyright 1998  Peter J.C.Clare                    */
  4. /*                                                                           */
  5. /*****************************************************************************/
  6. /*                                                                           */
  7. /*                                                                           */
  8. /*      Module name:    carnival.c                                           */
  9. /*                                                                           */
  10. /*      Creation date:  15/03/98                Revision date:  09/01/99     */
  11. /*                                                                           */
  12. /*      Produced by:    Peter J.C.Clare                                      */
  13. /*                                                                           */
  14. /*                                                                           */
  15. /*      Abstract:                                                            */
  16. /*                                                                           */
  17. /*              MAME sound & music driver for Sega/Gremlin Carnival.         */
  18. /*                                                                           */
  19. /*****************************************************************************/
  20. /*                                                                           */
  21. /*      Acknowledgements:                                                    */
  22. /*                                                                           */
  23. /*      Mike Coates, for the original Carnival MAME sound driver.            */
  24. /*      Virtu-Al, for the sound samples & hardware information.              */
  25. /*      The MAME Team, for the emulator framework.                           */
  26. /*                                                                           */
  27. /*****************************************************************************/
  28. /*                                                                           */
  29. /*      Revision history                                                     */
  30. /*      ================                                                     */
  31. /*                                                                           */
  32. /*      Date    Vsn.    Initials        Description                          */
  33. /*      ~~~~    ~~~~    ~~~~~~~~        ~~~~~~~~~~~                          */
  34. /*                                                                           */
  35. /*****************************************************************************/
  36.  
  37. #include "driver.h"
  38.  
  39.  
  40. #define CPU_MUSIC_ID            1       /* music CPU id number */
  41.  
  42.  
  43. /* output port 0x01 definitions - sound effect drive outputs */
  44. #define OUT_PORT_1_RIFLE_SHOT   0x01
  45. #define OUT_PORT_1_CLANG        0x02
  46. #define OUT_PORT_1_DUCK_1       0x04
  47. #define OUT_PORT_1_DUCK_2       0x08
  48. #define OUT_PORT_1_DUCK_3       0x10
  49. #define OUT_PORT_1_PIPE_HIT     0x20
  50. #define OUT_PORT_1_BONUS_1      0x40
  51. #define OUT_PORT_1_BONUS_2      0x80
  52.  
  53.  
  54. /* output port 0x02 definitions - sound effect drive outputs */
  55. #define OUT_PORT_2_BEAR         0x04
  56. #define OUT_PORT_2_MUSIC_T1     0x08
  57. #define OUT_PORT_2_MUSIC_RESET  0x10
  58. #define OUT_PORT_2_RANKING      0x20
  59.  
  60.  
  61. /* music CPU port definitions */
  62. #define MUSIC_PORT2_PSG_BDIR    0x40    /* bit 6 on P2 */
  63. #define MUSIC_PORT2_PSG_BC1     0x80    /* bit 7 on P2 */
  64.  
  65.  
  66. #define PSG_BC_INACTIVE         0
  67. #define PSG_BC_READ             MUSIC_PORT2_PSG_BC1
  68. #define PSG_BC_WRITE            MUSIC_PORT2_PSG_BDIR
  69. #define PSG_BC_LATCH_ADDRESS    ( MUSIC_PORT2_PSG_BDIR | MUSIC_PORT2_PSG_BC1 )
  70.  
  71.  
  72. #define PLAY(id,loop)           sample_start( id, id, loop )
  73. #define STOP(id)                sample_stop( id )
  74.  
  75.  
  76. /* sample file names */
  77. const char *carnival_sample_names[] =
  78. {
  79.     "*carnival",
  80.     "bear.wav",
  81.     "bonus1.wav",
  82.     "bonus2.wav",
  83.     "clang.wav",
  84.     "duck1.wav",
  85.     "duck2.wav",
  86.     "duck3.wav",
  87.     "pipehit.wav",
  88.     "ranking.wav",
  89.     "rifle.wav",
  90.     0
  91. };
  92.  
  93. /* sample sound IDs - must match sample file name table above */
  94. enum
  95. {
  96.     SND_BEAR = 0,
  97.     SND_BONUS_1,
  98.     SND_BONUS_2,
  99.     SND_CLANG,
  100.     SND_DUCK_1,
  101.     SND_DUCK_2,
  102.     SND_DUCK_3,
  103.     SND_PIPE_HIT,
  104.     SND_RANKING,
  105.     SND_RIFLE_SHOT
  106. };
  107.  
  108.  
  109. static int port2State = 0;
  110. static int psgData = 0;
  111.  
  112.  
  113. WRITE_HANDLER( carnival_sh_port1_w )
  114. {
  115.     static int port1State = 0;
  116.     int bitsChanged;
  117.     int bitsGoneHigh;
  118.     int bitsGoneLow;
  119.  
  120.  
  121.     /* U64 74LS374 8 bit latch */
  122.  
  123.     /* bit 0: connector pin 36 - rifle shot */
  124.     /* bit 1: connector pin 35 - clang */
  125.     /* bit 2: connector pin 33 - duck #1 */
  126.     /* bit 3: connector pin 34 - duck #2 */
  127.     /* bit 4: connector pin 32 - duck #3 */
  128.     /* bit 5: connector pin 31 - pipe hit */
  129.     /* bit 6: connector pin 30 - bonus #1 */
  130.     /* bit 7: connector pin 29 - bonus #2 */
  131.  
  132.     bitsChanged  = port1State ^ data;
  133.     bitsGoneHigh = bitsChanged & data;
  134.     bitsGoneLow  = bitsChanged & ~data;
  135.  
  136.     port1State = data;
  137.  
  138.     if ( bitsGoneLow & OUT_PORT_1_RIFLE_SHOT )
  139.     {
  140.         PLAY( SND_RIFLE_SHOT, 0 );
  141.     }
  142.  
  143.     if ( bitsGoneLow & OUT_PORT_1_CLANG )
  144.     {
  145.         PLAY( SND_CLANG, 0 );
  146.     }
  147.     if ( bitsGoneHigh & OUT_PORT_1_CLANG )
  148.     {
  149.         STOP( SND_CLANG );
  150.     }
  151.  
  152.     if ( bitsGoneLow & OUT_PORT_1_DUCK_1 )
  153.     {
  154.         PLAY( SND_DUCK_1, 1 );
  155.     }
  156.     if ( bitsGoneHigh & OUT_PORT_1_DUCK_1 )
  157.     {
  158.         STOP( SND_DUCK_1 );
  159.     }
  160.  
  161.     if ( bitsGoneLow & OUT_PORT_1_DUCK_2 )
  162.     {
  163.         PLAY( SND_DUCK_2, 1 );
  164.     }
  165.     if ( bitsGoneHigh & OUT_PORT_1_DUCK_2 )
  166.     {
  167.         STOP( SND_DUCK_2 );
  168.     }
  169.  
  170.     if ( bitsGoneLow & OUT_PORT_1_DUCK_3 )
  171.     {
  172.         PLAY( SND_DUCK_3, 1 );
  173.     }
  174.     if ( bitsGoneHigh & OUT_PORT_1_DUCK_3 )
  175.     {
  176.         STOP( SND_DUCK_3 );
  177.     }
  178.  
  179.     if ( bitsGoneLow & OUT_PORT_1_PIPE_HIT )
  180.     {
  181.         PLAY( SND_PIPE_HIT, 0 );
  182.     }
  183.  
  184.     if ( bitsGoneLow & OUT_PORT_1_BONUS_1 )
  185.     {
  186.         PLAY( SND_BONUS_1, 0 );
  187.     }
  188.  
  189.     if ( bitsGoneLow & OUT_PORT_1_BONUS_2 )
  190.     {
  191.         PLAY( SND_BONUS_2, 0 );
  192.     }
  193. }
  194.  
  195.  
  196. WRITE_HANDLER( carnival_sh_port2_w )
  197. {
  198.     int bitsChanged;
  199.     int bitsGoneHigh;
  200.     int bitsGoneLow;
  201.  
  202.     /* U63 74LS374 8 bit latch */
  203.  
  204.     /* bit 0: connector pin 48 */
  205.     /* bit 1: connector pin 47 */
  206.     /* bit 2: connector pin 45 - bear */
  207.     /* bit 3: connector pin 46 - Music !T1 input */
  208.     /* bit 4: connector pin 44 - Music reset */
  209.     /* bit 5: connector pin 43 - ranking */
  210.     /* bit 6: connector pin 42 */
  211.     /* bit 7: connector pin 41 */
  212.  
  213.     bitsChanged  = port2State ^ data;
  214.     bitsGoneHigh = bitsChanged & data;
  215.     bitsGoneLow  = bitsChanged & ~data;
  216.  
  217.     port2State = data;
  218.  
  219.     if ( bitsGoneLow & OUT_PORT_2_BEAR )
  220.     {
  221.         PLAY( SND_BEAR, 0 );
  222.     }
  223.  
  224.     if ( bitsGoneLow & OUT_PORT_2_RANKING )
  225.     {
  226.         PLAY( SND_RANKING, 0 );
  227.     }
  228.  
  229.     if ( bitsGoneHigh & OUT_PORT_2_MUSIC_RESET )
  230.     {
  231.         /* reset output is no longer asserted active low */
  232.         cpu_set_reset_line( CPU_MUSIC_ID, PULSE_LINE );
  233.     }
  234. }
  235.  
  236.  
  237. READ_HANDLER( carnival_music_port_t1_r )
  238. {
  239.     /* note: 8039 T1 signal is inverted on music board */
  240.     return ( port2State & OUT_PORT_2_MUSIC_T1 ) ? 0 : 1;
  241. }
  242.  
  243.  
  244. WRITE_HANDLER( carnival_music_port_1_w )
  245. {
  246.     psgData = data;
  247. }
  248.  
  249.  
  250. WRITE_HANDLER( carnival_music_port_2_w )
  251. {
  252.     static int psgSelect = 0;
  253.     int newSelect;
  254.  
  255.     newSelect = data & ( MUSIC_PORT2_PSG_BDIR | MUSIC_PORT2_PSG_BC1 );
  256.     if ( psgSelect != newSelect )
  257.     {
  258.         psgSelect = newSelect;
  259.  
  260.         switch ( psgSelect )
  261.         {
  262.         case PSG_BC_INACTIVE:
  263.             /* do nowt */
  264.             break;
  265.  
  266.         case PSG_BC_READ:
  267.             /* not very sensible for a write */
  268.             break;
  269.  
  270.         case PSG_BC_WRITE:
  271.             AY8910_write_port_0_w( 0, psgData );
  272.             break;
  273.  
  274.         case PSG_BC_LATCH_ADDRESS:
  275.             AY8910_control_port_0_w( 0, psgData );
  276.             break;
  277.         }
  278.     }
  279. }
  280.